package com.fyl.validation;

import com.fyl.validation.aop.ValidationAdvisor;
import com.fyl.validation.aop.ValidationMethodInterceptor;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Role;

@Configuration
public class ValidationConfiguration {

    @Bean
    @Role(BeanDefinition.ROLE_INFRASTRUCTURE)
    @ConditionalOnMissingBean
    public ValidationMethodInterceptor validateMethodInterceptor() {
        return new ValidationMethodInterceptor();
    }

    @Bean
    @Role(BeanDefinition.ROLE_INFRASTRUCTURE)
    @ConditionalOnMissingBean
    public ValidationAdvisor validateAdvisor(ValidationMethodInterceptor validationMethodInterceptor) {
        return new ValidationAdvisor(validationMethodInterceptor);
    }
}
